#include "ShowFindUpdate.h"

void ShowFindUpdateKLB::show(vector<Product> other)
{
	sort(other.begin(), other.end(), sort_price);
	for(int i = 0; i < other.size();i++)
	{
		cout << other[i].name_get() << " " << other[i].id_get() << " " << other[i].price_get() << endl;
	}
}

/*double ShowFindUpdateKLB::getProductPrice(int prod_id, vector<Product> prods)
{
	for(int i = 0;  i< prods.size(); i++)
	{
		if (prod_id == prods[i].id_get())
		{
			return prods[i].price_get();
		}
	}
	return 0;
}*/

void ShowFindUpdateKLB::find(vector<Category> catList, vector<Product> prods, vector<Cart_item> cart_item)
{
	for(int i = 0; i < catList.size(); i++)
	{
		double sum = 0;
		for(int j = 0; j < prods.size(); ++j)
		{
			if(prods[j].cat_get() == catList[i].id_get())	//changed cat_id to getCat_id
			{
				for(int z = 0; z < cart_item.size(); ++z)
				{
					if(cart_item[z].prod_get() == prods[j].id_get())		//change sucks
					{
						// double curPrice = getProductPrice(cart_item[z].prod_get(), prods);
						sum += cart_item[z].qty_get() * prods[j].price_get();
					}
				}
			}
		}
		cout << catList[i].name_get() << ":" << sum << endl;
	}
	
}
void ShowFindUpdateKLB::update(vector<Cart_item>& cart_items)
{      //asks for for data so it can add it to the vector Cart_item
	int cartItemId_Input;
	int cartId_Input;
	int prodId_Input;
	int prodQuantity_Input;
	cout << "It seems you would like to add your own cart item, if so please enter a \n"
		 << "a cart item ID: ";
	cin  >> cartItemId_Input;
	cout << "a cart Id: " ;
	cin  >> cartId_Input;
	cout << "a product Id: ";
	cin  >> prodId_Input;
	cout << "quantities of the product: ";
	cin  >> prodQuantity_Input;
	Cart_item NewCart_item (cartItemId_Input, cartId_Input, prodId_Input, prodQuantity_Input);
	cart_items.push_back(NewCart_item);
}

bool ShowFindUpdateKLB::sort_price(Product a, Product b)
{
  return (a.price_get() < b.price_get());
}
